﻿using System;
using System.Collections.Generic;
using System.Text;
using PostSharp.Aspects.Dependencies;
using System.Reflection;

namespace Arcana.Contract.Argument.Is.Not
{
    /// <summary>
    /// Specifies that an argument can not be <b>null</b>.
    /// </summary>
    /// <exception cref="ArgumentNullException">The contract has failed.</exception>
    /// <exception cref="InvalidOperationException"><i>argument</i> was not found.</exception>
    [Serializable]
    [AspectRoleDependency(AspectDependencyAction.Order, AspectDependencyPosition.Before, Roles.Conditional)]
    [ProvideAspectRole(Roles.Contract)]
    [ProvideAspectRole(Roles.Method)]
    [ProvideAspectRole(Roles.Argument)]
    [ProvideAspectRole(Roles.NullCheck)]
    public sealed class NullAttribute : ContractBase
    {
        /// <summary>
        /// Initializes a new instance of <b>Argument.Is.Not.NullAttribute</b>
        /// </summary>
        /// <param name="parameterName">The parameter name to which argument contract applies.</param>
        /// <exception cref="ArgumentNullException"><i>parameterName</i> is <b>null</b>.</exception>
        public NullAttribute(string argumentName) : base(argumentName)
        {
            Exception = typeof(ArgumentNullException);
        }

        protected override bool ValidateArgument(object argument)
        {
            return argument != null;
        }
    }
}
